#!/bin/bash

mysql -uroot  -proot<<EOF
use result;
truncate mid.mid_vipLiveness;
truncate mid.mid_funnelSum;
EOF
#处理中间表
sh /home/marvin/realtime_job/main/mid_vipLiveness_main.sh
mysql -uroot  -proot<<EOF
use result;
replace into mid.mid_funnelSum
select A.montha,B.totalPeople
from
(select substr(date,1,7)as montha,max(date)as yuedi
from res_addVip
group by substr(date,1,7))as A
join res_addVip as B
on A.yuedi=B.date;
EOF
#实时处理 res_vipLiveness 表
mysql -uroot  -proot <<EOF
use result;
replace into res_vipLiveness
select A.month,A.sum-B.one-B.two-B.three-B.four-B.five-B.overFive,B.one,B.two,B.three,B.four,B.five,B.overFive
FROM mid.mid_funnelSum as A
join  mid.mid_vipLiveness as B
on A.month=B.month;
EOF

mysql -uroot  -proot -e "replace into result.res_update(res_table) VALUES('res_vipLiveness')"
